﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class frmupdatesevers : Form{
    
        public int stu;
        public frmupdatesevers()
        {
            InitializeComponent();
        }
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        public void tj()
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();

            string sql = "select userID,userName,userSex,userDian,userAdd,userBorn from dbo.UserTpye where userID= '"+stu+"'";
            SqlCommand comm = new SqlCommand(sql, conn);
            SqlDataReader reader = comm.ExecuteReader();
            if (reader.Read())
            {
                textBox1.Text = reader["userID"].ToString();
                textBox2.Text = reader["userName"].ToString();
                textBox3.Text = reader["userSex"].ToString();
                textBox4.Text = reader["userDian"].ToString();
                textBox5.Text = reader["userAdd"].ToString();
            }
        }
        private void frmupdatesevers_Load(object sender, EventArgs e)
        {
            tj();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            int bianhao = Convert.ToInt32(this.textBox1.Text);
            string name = this.textBox2.Text;
            string sex = this.textBox4.Text;
            string iphone = this.textBox5.Text;
            string IDnum = this.textBox6.Text;
            string js = this.textBox7.Text;
            string sql = "update dbo.UserTpye set userID='"+bianhao+"', userName='"+name+"',userSex='"+sex+"',userDian='"+iphone+"',userAdd='"+IDnum+"',userQi='"+js+"' where userID='"+bianhao+"';";
            SqlCommand cmd = new SqlCommand(sql,conn);
            int i=cmd.ExecuteNonQuery();
            if (i>0)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
